package com.umgsai.thread.thread56;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Task {
	private static Timer timer = new Timer();
	static public class MyTask1 extends TimerTask{
		@Override
		public void run() {
			System.out.println("Task1运行了，时间为：" + new Date());
			timer.cancel();
		}
	}
	static public class MyTask2 extends TimerTask{
		@Override
		public void run() {
			System.out.println("Task2运行了，时间为：" + new Date());
		}
	}
	public static void main(String[] args) {
		try {
			MyTask1 myTask1 = new MyTask1();
			MyTask2 myTask2 = new MyTask2();
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String dateString1 = "2016-07-09 22:08:19";
			String dateString2 = "2016-07-09 22:08:29";
			Date date1 = sdf1.parse(dateString1);
			Date date2 = sdf2.parse(dateString2);
			System.out.println("main启动时间为：" + new Date());
			timer.schedule(myTask1, date1, 4000);
			timer.schedule(myTask2, date2, 4000);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
